﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Buddy.BehaviorTree;
using Buddy.CommonBot;
using Buddy.CommonBot.Logic;
using Buddy.Swtor;
using WingIt.Dynamics;

namespace WingIt.Routines.Basic
{
    public class AgentBasic
    {
        [Class(CharacterClass.Agent)]
        [Behavior(BehaviorType.Combat)]
        public static Composite AgentCombat()
        {
            //Neo93 29.04.2012
            //if the bot is on gcd and the target is moving, it pops out of crouch
            return new PrioritySelector(
                Spell.WaitForCast(),
                Movement.StopInRange(2.8f),
                //***Generel***
                Spell.Cast("Escape ", castWhen => BuddyTor.Me.IsStunned),//CC Break
                Spell.Cast("Crouch", ret => BuddyTor.Me.CurrentTarget.InLineOfSight && !BuddyTor.Me.HasBuff("Crouch") && !BuddyTor.Me.HasBuff("Cover") && BuddyTor.Me.CurrentTarget.Distance <= 2.8f),

                //CC
                Spell.Cast("Flash Bang", onUnit =>
                {
                    var previousTarget = BuddyTor.Me.CurrentTarget;
                    return
                        Helpers.Targets.FirstOrDefault(
                            t =>
                            t != previousTarget && (t.Toughness == CombatToughness.Strong)) ??
                        Helpers.Targets.FirstOrDefault(t => t != previousTarget);
                }, castWhen => Helpers.Targets.Count() >= 3),

                //Offensive
                //Spell.Cast("Rifle Shot", castWhen => (BuddyTor.Me.CurrentTarget.Toughness == CombatToughness.Standard || BuddyTor.Me.CurrentTarget.Toughness == CombatToughness.Weak) && BuddyTor.Me.CurrentTarget.HealthPercent <= 25),//No Resource needed
                Spell.Cast("Corrosive Dart", ctx => BuddyTor.Me.ResourceStat >= 80 && BuddyTor.Me.CurrentTarget.Toughness != CombatToughness.Standard && BuddyTor.Me.CurrentTarget.Toughness != CombatToughness.Weak && !BuddyTor.Me.CurrentTarget.HasBuff("Poisoned (Tech)")),//Bleed
                Spell.Cast("Explosive Probe", castWhen => (BuddyTor.Me.HasBuff("Crouch") || BuddyTor.Me.HasBuff("Cover")) && BuddyTor.Me.ResourceStat >= 80 && BuddyTor.Me.CurrentTarget.Distance <= 2.8f),
                Spell.Cast("Fragmentation Grenade", castWhen => Helpers.Targets.Count() >= 3),//AoE
                Spell.Cast("Debilitate", castWhen => BuddyTor.Me.CurrentTarget.Distance <= 1f && BuddyTor.Me.ResourceStat >= 70),//Stun 
                Spell.Cast("Overload Shot", castWhen => BuddyTor.Me.ResourceStat >= 77 && BuddyTor.Me.CurrentTarget.Distance <= 1f),//Nice dmg shot
                Spell.Cast("Snipe", castWhen => (BuddyTor.Me.HasBuff("Crouch") || BuddyTor.Me.HasBuff("Cover")) && BuddyTor.Me.ResourceStat >= 70 && BuddyTor.Me.CurrentTarget.Distance <= 2.8f),
                Spell.Cast("Shiv", castWhen => BuddyTor.Me.CurrentTarget.Distance <= 0.4f && BuddyTor.Me.ResourceStat >= 75),//melee attack
                Spell.Cast("Rifle Shot"),//No Resource needed

                Movement.MoveTo(ret => BuddyTor.Me.CurrentTarget.Position, 2.8f)
                );
        }

        /*[Class(CharacterClass.Agent)]
        [Behavior(BehaviorType.OutOfCombat)]
        public static Composite AgentOutOfCombat()
        {
        }
         * */

        [Class(CharacterClass.Agent)]
        [Behavior(BehaviorType.Pull)]
        public static Composite AgentPull()
        {
            return AgentCombat();
        }
    }
}
